package com.housekeeping.housekeeping.administrator.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class Dbmanage {
    private static DataSource dataSource=null;
    public static final String PROPERTIES="jdbc.properties";
    static {
        Properties properties = new Properties();
        try {
            properties.load(Dbmanage.class.getClassLoader().getResourceAsStream(PROPERTIES));
            dataSource= DruidDataSourceFactory.createDataSource(properties);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
    public static void close(AutoCloseable ... closeables){
        for (AutoCloseable close:closeables) {
            try {
                close.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}
